﻿using AutoMapper;
using banyuetan_2_0.Model.Models;
using banyuetan_2_0.Model.ViewModels;

namespace banyuetan_2_0.AutoMapper
{
    public class CustomProfile : Profile
    {
        /// <summary>
        /// 配置构造函数，用来创建关系映射
        /// </summary>
        public CustomProfile()
        {
            CreateMap<BlogArticle, BlogViewModels>();
            CreateMap<BlogViewModels, BlogArticle>();

            CreateMap<Category, CategoryViewModel>()
                .ForMember(destinationMember=>destinationMember.ParentCategoryName,memberOptions=>memberOptions.MapFrom(sourceMember=>sourceMember.ParentCategory.cName))
                .ForMember(destinationMember=>destinationMember.CreateUserName,memberOptions=>memberOptions.MapFrom(sourceMember=>sourceMember.sysUserInfo.uRealName));
            CreateMap<CategoryViewModel, Category>();

            CreateMap<Article, ArticleViewModel>()
                .ForMember(destinationMember=>destinationMember.aTitlePicPath,memberOptions=>memberOptions.MapFrom(sourceMember=>sourceMember.aTitlePic.sPath))
                .ForMember(destinationMember=>destinationMember.aEditorRealName,memberOptions=>memberOptions.MapFrom(sourceMember=>sourceMember.aEditor.uRealName));
            CreateMap<ArticleViewModelForCreate,Article>();
        }
    }
}
